package com.elmcode.server.utils;

import lombok.Data;


@Data
public class Result<T> {

    private String msg;
    private int code = 200;
    private Integer total;//记录数
    private T data;

    public static <T> Result ok(String msg,T data){
        Result result = new Result();
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result ok(String msg,T data,Integer total){
        Result result = new Result();
        result.setMsg(msg);
        result.setData(data);
        result.setTotal(total);
        return result;
    }

    public static Result ok(String msg){
        Result result = new Result();
        result.setMsg(msg);
        return result;
    }

    public static Result error(String msg,Integer code){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(code);
        return result;
    }

    public static Result error(String msg){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(500);
        return result;
    }

}
